*** Settings ***
Documentation    TC01-Create a new LCL Project
Resource    ../../Keywords/Common_Head.robot
Resource    ../../Keywords/Common/Common_kw.robot
Force Tags    P1
Metadata    Author    Terence
Metadata    ID    6850935


*** Test Cases ***
TC01-Create a new LCL Project
    Step 1 User Goes To Basic Data Management Tender List
    Step 2 User Goes To Pricing Collaboration Pricing Project
    Step 3 User Inputs Tender ID Such As 20240815 In The Tender ID
    Step 4 User Chooses The 20240815 Regression From The Dropdown
    Step 5 User Clicks Dropdown List From Mode Field
    Step 6 User Chooses LCL From The Dropdown List
    Step 7 User Selects The current Date 10 11 30 00 For Deadline
    Step 8 User Selects The current Date For Rate Validity From
    Step 9 User Clicks Deputy Button
    Step 10 User Inputs MARYMA01 In The SIMS ID Field Clicks Search
    Step 11 User Clicks Select Button
    Step 12 User Clicks Upload Button Add File Button In The Upload
    Step 13 User Checks The Information At The Bottom Of This
    Step 14 User Clicks Save Button
    Step 15 User Selects TenderID Contains 20240815
    Step 16 Select This Project Click On Delete Project Button
    Step 17 User Goes To Basic Data Management Tender List 17



*** Keywords ***
Step ${step} User Goes To Basic Data Management Tender List
    #************************Step 1******************************
    #  Do:
    #      User goes to Basic Data Management Tender List
    #      Click Create button
    #      Input with following attributes
    #      Tender ID some numbers such as 202408151435001 you can
    #     input with current datetime and some random number to
    #     avoid duplicate validation
    #      Tender Title some value such as Regression Test by
    #     Wendy001
    #      Customer 815 Miele
    #      Mode select all
    #      Level Global
    #      Click on Save button
    #  Expected:
    #      Created successfully with the message Tender has been
    #     added
    #************************************************************
    Login Space
    ${G_TENDERID}    Generate Tender ID
    ${TenderTitle}   Set Variable    Regression Test by Wendy001
    Set Suite Variable     ${G_TENDERID}    ${G_TENDERID}
    Set Suite Variable     ${TenderTitle}    ${TenderTitle}
    Create Tender    ${G_TENDERID}    ${TenderTitle}    815    true    true    true

Step ${step} User Goes To Pricing Collaboration Pricing Project
    #************************Step 2******************************
    #  Do:
    #      User goes to Pricing Collaboration Pricing Project
    #      User clicks Create Project button
    #  Expected:
    #      A New Project dialog should be opened successfully
    #************************************************************
    Wait Until Keyword Succeeds    5x    100ms    Click   ${navigation_pricing_project}
    Wait For Elements State    ${Project_toolbar_CreateButton}    visible    10
    Wait Until Search Finished
    Wait Until Keyword Succeeds    5x    100ms    Click    ${Project_toolbar_CreateButton}
    Wait For Elements State   ${Project_create_TenderID}     enabled

Step ${step} User Inputs Tender ID Such As 20240815 In The Tender ID
    #************************Step 3******************************
    #  Do:
    #      User inputs Tender ID such as 20240815 in the Tender ID
    #     field
    #  Expected:
    #      A dropdown list 20240815 Regression comes up
    #************************************************************
    Fill Text    ${Project_create_TenderID}    ${G_TENDERID}
    Sleep    1
    Wait For Elements State    ${Project_create_TenderIdDropDown}    visible    60
    Wait Until Search Finished

Step ${step} User Chooses The 20240815 Regression From The Dropdown
    #************************Step 4******************************
    #  Do:
    #      User chooses the 20240815 Regression from the dropdown
    #     list
    #  Expected:
    #      Customer field should be fulfilled with Miele
    #      Vertical Market should be Consumer
    #      Level should be fulfilled with Global
    #************************************************************
    Click    ${Project_create_TenderIdDropDown}
    Wait Until Keyword Succeeds    5x    200ms    Check Text Value    ${Project_create_ProjectName}    ${G_TENDERID}-undefined-${TenderTitle}
    Get Text    css=#customer   ==   Miele
    Get Text    css=#verticalMarket   ==   Consumer
    Get Text    css=#level   ==   Global

Step ${step} User Clicks Dropdown List From Mode Field
    #************************Step 5******************************
    #  Do:
    #      User clicks dropdown list from Mode field
    #  Expected:
    #      There should be mode LCL from the dropdown list
    #************************************************************
    Get Select Options    select[id='mode']    validate    [v["label"] for v in value] == ["--please select a mode--","AIR", "FCL", "LCL"]

Step ${step} User Chooses LCL From The Dropdown List
    #************************Step 6******************************
    #  Do:
    #      User chooses LCL from the dropdown list
    #  Expected:
    #      The project Name field should be changed to be 20240815
    #     LCL Regression
    #************************************************************
    Select Options By   ${Project_create_Mode}    label    LCL

Step ${step} User Selects The current Date 10 11 30 00 For Deadline
    #************************Step 7******************************
    #  Do:
    #      User selects the current date 10 11 30 00 for Deadline
    #     to TM field
    #  Expected:
    #      The current date 10 11 30 00 should be input
    #     successfully
    #************************************************************
    ${DeadLine_Date}    Get Current Date    UTC    +10days    result_format=%d/%m/%Y
    Fill Text    ${Project_create_DeadlinetoTMDate}    ${DeadLine_Date}
    Select Options By    ${Project_create_DeadlinetoTMHour}    label    11
    Select Options By    ${Project_create_DeadlinetoTMMinute}    label    30


Step ${step} User Selects The current Date For Rate Validity From
    #************************Step 8******************************
    #  Do:
    #      User selects the current date for Rate Validity From
    #      User selects the current date 30 for Rate Validity To
    #  Expected:
    #      They both should be input successfully
    #************************************************************
    ${DeadLine_Date}    Get Current Date    UTC    result_format=%d/%m/%Y
    Fill Text    ${Project_create_RateValidityFrom}    ${DeadLine_Date}
    ${DeadLine_Date}    Get Current Date    UTC    +30days    result_format=%d/%m/%Y
    Fill Text    ${Project_create_RateValidityTo}   ${DeadLine_Date}

Step ${step} User Clicks Deputy Button
    #************************Step 9******************************
    #  Do:
    #      User clicks Deputy button
    #  Expected:
    #      The User locator dialog should be opened
    #************************************************************
    Wait Until Keyword Succeeds    5x    300ms    Click    ${Project_create_Deputies}
    Wait For Elements State    //h4[.="Select User"]

Step ${step} User Inputs MARYMA01 In The SIMS ID Field Clicks Search
    #************************Step 10******************************
    #  Do:
    #      User inputs MARYMA01 in the SIMS ID field clicks search
    #     button
    #  Expected:
    #      The MARYMA01 should be searched out
    #************************************************************
    # MARYMA01 can't be found ,change another SIMSID
    ${DEPUTY}    Set Variable    NATZHANG
    Set Test Variable    ${DEPUTY}    ${DEPUTY}
    Wait For Elements State   Select[data-ng-change="selectedCriterion(qe.id, 'simsId')"]     enabled    30
    Fill Text     css = [data-type-validation='Joose.Type.Str']    ${DEPUTY}
    Click    ${user_locator_search_button} 
    Wait For Elements State    xpath=//td[.='${DEPUTY}']    visible

Step ${step} User Clicks Select Button
    #************************Step 11******************************
    #  Do:
    #      User clicks select button
    #  Expected:
    #      The User locator dialog should be closed and MARYMA01
    #     should be added into the Deputy
    #************************************************************
    Click    xpath=//td[.='${DEPUTY}']
    Click    ${user_locator_selectButton} 
    Wait Until Search Finished
    Wait For Elements State    //span[contains(text(),"${DEPUTY}")]

Step ${step} User Clicks Upload Button Add File Button In The Upload
    #************************Step 12******************************
    #  Do:
    #      User clicks upload button add file button in the Upload
    #     Template dialog choose a file
    #  Expected:
    #      The file should be uploaded successfully in the
    #     document section
    #************************************************************
    # ${DOWNLOAD_PATH}     Normalize Path    ${DOWNLOAD_PATH}
    # ${Upload_File}    Set Variable    ${DOWNLOAD_PATH}${/}LCL_UPLOADFILE.TXT
    # Create File    ${Upload_File}
    # Append To File    ${Upload_File}    123Test    
    Wait Until Keyword Succeeds    5x    300ms    Click    ${Project_create_UploadButton}
    Wait For Elements State   ${upload_addFileButton}     enabled
    Upload File By Selector    ${upload_addFileButton}    ${CURDIR}${/}TestData${/}LCLTemplate-Port-all.xlsx

Step ${step} User Checks The Information At The Bottom Of This
    #************************Step 13******************************
    #  Do:
    #      User checks the information at the bottom of this
    #     dialog
    #  Expected:
    #      The Project Owner should be current user name SIMS ID
    #      Create Date should be current system date
    #      Status should be In Progress
    #************************************************************
    Check Text Value    ${Project_create_ProjectOwner}    ${USERNAME_FULL}
    ${CurrentDate}    Get Current Date      result_format=%d/%m/%Y
    Check Text Value    ${Project_create_CreateDate}    ${CurrentDate}
    Check Text Value    ${Project_create_Status}    In Progress

Step ${step} User Clicks Save Button
    #************************Step 14******************************
    #  Do:
    #      User clicks save button
    #  Expected:
    #      The project should be saved at the top of the project
    #     list
    #************************************************************
    Wait Until Search Finished
    Wait Until Keyword Succeeds    5x    300ms    Click    ${Project_create_SaveButton}
    Wait Until Search Finished

Step ${step} User Selects TenderID Contains 20240815
    #************************Step 15******************************
    #  Do:
    #      User selects TenderID Contains 20240815
    #  Expected:
    #      The project could be found
    #************************************************************
    Wait For Elements State    //td[contains(text(),"${G_TENDERID}")]


Step ${step} Select This Project Click On Delete Project Button
    #************************Step 16******************************
    #  Do:
    #      Select this project click on Delete Project button
    #      Click Yes of the pop up confirm window
    #  Expected:
    #      System displays Project has been deleted
    #************************************************************
#     Delete Project    ${G_TENDERID}
    Log    Finish In Teardown

Step ${step} User Goes To Basic Data Management Tender List 17
    #************************Step 17******************************
    #  Do:
    #      User goes to Basic Data Management Tender List
    #      Search out the tender created in step1
    #      Click on Delete button
    #      Click on Yes button in the popup dialog
    #  Expected:
    #      System displays Tender has been deleted
    #************************************************************
#     Delete Tender    ${G_TENDERID}
    Log    Finish In Teardown

